/*
 * $HeadURL:  $
 *
 * Copyright (c) 2007 Drutt Corporation, all rights reserved.
 *
 */
package homework.james.xiao.bean;


import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;

import com.thoughtworks.xstream.annotations.XStreamAlias;

/**
 * @author eyngxao
 * @version $Revision: $
 * 一次订购记录，由若干个order组成，加注日期信息
 */
@XStreamAlias("orders") 
public class Orders {

	/** Class revision */
	public static final String _REV_ID_ = "$Revision: $";
	private LinkedList<Order> orders = new LinkedList<Order>();
	private String date;
	
	public Orders(LinkedList<Order> o, String d){
		setOrders(o);
		setDate(d);
	}
	public Orders(){
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String date = sdf.format(new Date());
		setDate(date);
	}
	public LinkedList<Order> getOrders() {
		return orders;
	}
	public void setOrders(LinkedList<Order> orders) {
		this.orders = orders;
	}
	public void addOrder(Order o){
		orders.add(o);
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public void print(PrintWriter ps, boolean withHeader, boolean withBotton) {
		if(this.getOrders()!=null&&this.getOrders().size()==0){
			ps.println("Your order is empty.");
			return;
		}
		String border = "|===============================================|";
		
		
		if(withHeader){
			ps.println(border);	
			ps.println("| No. |\t User\t|\tDish\t\t| Price\t|");
		}
		ps.println("|================"+date+"=====================|");
		int number = 1;
		for(Order order:this.getOrders()){
			ps.println("|  "+number +"  "+order);
			number++;
		}
		if(withBotton)
		ps.println(border);
		
	}
}
